<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Proposal extends CI_Controller {

	function __construct()
	{
		parent::__construct();
		
		 $this->load->helper(array('form', 'url'));
		 $this->load->helper('array');
		// check if user logged in 
		if (!$this->ion_auth->logged_in())
	  	{
			redirect('auth/login');
	  	}		
		 $this->load->model('user/caller/proposal_model');			
	}

	function index()
   {
	 $meta['page_title'] = "Proposal";
	
	 $data['modules'] = $this->proposal_model->get_all_modules();
     $data['category']=	$this->proposal_model->get_all_category(); 
	  $data['section']=	$this->proposal_model->get_all_section(); 
	  $data['proposal']=$this->proposal_model->get_all_proposal(); 
     $this->load->view('common/header', $meta);
     $this->load->view('user/caller/proposal',$data);
     $this->load->view('common/footer');
   }
   function get_section()
   {
    $category=$this->input->post("proid");
	$data['getsection']=$this->proposal_model->get_section($category);
	foreach( $data['getsection'] as $section)
	{
	$id=$section->id; 
    $name=$section->name; 
  echo "<option value=$id>$name </option>";}
   }
   function get_module()
   {
    $id =$this->input->post("proid");
	$data['section']=$this->proposal_model->get_module($id);
	foreach($data['section'] as $module)
	{
    $id=$module->id;
	$name=$module->name;
   echo "<option value=$id>$name </option>";
    }
   }
    function getallmodule()
	{
	$id =$this->input->post("proid");
	$data['getallmodule']=$this->proposal_model->getallmodule($id);
	$this->load->view('user/caller/allmodule',$data);
	
	}

	  function pdf()
     {
     $this->load->helper(array('dompdf', 'file'));
	 
	 $data=$this->input->post("hidden");
	 $html=$data;
	 
     pdf_create($html, 'filename');    
      }

	
	function view_proposal()
		{
		 
		$data['id']=$this->proposal_model->getcategoryid($_REQUEST['proposaldelete']);
		foreach ($data['id'] as $id){
		$id= $id->category_id;
		 $insert = array(
		'section_body'=>$this->proposal_model->getsectionbody($id),
	   'section_footer'=>$this->proposal_model->getsectionfooter($id),
	   'proposal_detail'=>$this->proposal_model->getproposaldetail($_REQUEST['proposaldelete']),);
	    $meta['page_title'] = "proposal_view";
	    $this->load->view('common/header', $meta);
		 $this->load->view('user/caller/pre');
	   $this->load->view('user/caller/view_proposal',$insert);
        $this->load->view('common/footer');}}
	//for proposalpreview
	 function proposal_preview()
     {
	
	   $insert = array(
	  'user_name'  => $_REQUEST['user_name'],
   	   'user_company' => $_REQUEST['user_company'],
   	   'user_address' => $_REQUEST['user_address'],
	   'client_name' => $_REQUEST['client_names'],
	  'client_address' => $_REQUEST['client_addresss'],
	    'category_id' => $_REQUEST['proposal_category'],
	   'proposal_name' => $_REQUEST['proposal_name'],
   	  'proposal_description' => $_REQUEST['proposal_desc'],	
	  'section_body'=>$this->proposal_model->getsectionbody( $_REQUEST['proposal_category']),
	   'section_footer'=>$this->proposal_model->getsectionfooter( $_REQUEST['proposal_category']),);
	     $meta['page_title'] = "Preview";
	    $this->load->view('common/header', $meta);
	      $this->load->view('user/caller/preview',$insert);
        $this->load->view('common/footer');}
	  //for proposal
     function create_proposal()
   {
   
   $insert = array(
	   'user_name' => $_REQUEST['user_name'],
   	   'user_company' => $_REQUEST['user_company'],
   	   'user_address' => $_REQUEST['user_address'],
	   'client_name' => $_REQUEST['client_name'],
	  'client_address' => $_REQUEST['client_address'],
	    'category_id' => $_REQUEST['proposal_category'],
	   'proposal_name' => $_REQUEST['proposal_name'],
   	  'proposal_description' => $_REQUEST['proposal_desc'], );
	   $this->proposal_model->create_proposal($insert); }
	    
		function create_module()
       {
	   $insert = array(
	   'name' => $_REQUEST['module_name'],
   	   'description' => $_REQUEST['module_desc'],
   	   'price' => $_REQUEST['module_price'],
	   'days_required'=>$_REQUEST['module_days'],
   	   'section_id' => $_REQUEST['module_type'],	   
	   );
	   $this->proposal_model->create_module($insert);
	    }
	//for category	
    function create_category()
	{
	   $insert = array(
	   'name' => $_REQUEST['category_name'],
   	   'description' => $_REQUEST['category_desc'],
   	     );
	   $this->proposal_model->create_categories($insert);
	}
	//section
	 function create_section()
	{
	   $insert = array(
	   'name' => $_REQUEST['section_name'],
   	   'position' => $_REQUEST['section_position'],
	    'category_id' => $_REQUEST['section_category'],
   	     );
	   $this->proposal_model->create_section($insert);
	}
   //feature
   
    function create_feature()
   {
	   $insert = array(
	   'name' => $_REQUEST['feature_name'],
   	   'description' => $_REQUEST['feature_desc'],
   	   'price' => $_REQUEST['feature_price'],
   	   'module_id' => $_REQUEST['feature_type'],	   
	   );
	   
	  // print_r($insert);
	//  exit;
	   $this->proposal_model->create_feature($insert);
	    }
		function deletemodule()
		{
		 $id=$this->input->post('id');
      $this->proposal_model->delete_module($id);
		}
		function deletefeature()
		{
		 $id=$this->input->post('id');
        $this->proposal_model->delete_feature($id);
		}
		function deletecategory()
		{
		 $id=$this->input->post('id');
        $this->proposal_model->delete_category($id);
		}
		function deleteproposal()
		{
		 $id=$this->input->post('id');
        $this->proposal_model->delete_proposal($id);
		}
		
		 function update_module()
       {
	  
	  if($this->input->post('update'))
	   {
	  $id=$this->input->post('hidden');
	 $name=$this->input->post('mname');
	 $description=$this->input->post('moddesc');
	 $price=$this->input->post('appendedPrependedInput');
	 $this->proposal_model->update_module($id,$name,$description,$price);
      }
     redirect('/user/proposal');
     }
	 	 function update_feature()
       {
	  if($this->input->post('featupdate'))
	   {
	  $id=$this->input->post('feathidden');
	 $name=$this->input->post('featname');
	 $description=$this->input->post('featdesc');
	 $price=$this->input->post('featprice');
	 $this->proposal_model->update_feature($id,$name,$description,$price);
      }
     redirect('/user/proposal');
     }
   
}?>